package com.dyx.source.nio;

import java.nio.channels.SelectionKey;

public class SelectorTest {

    public static void main(String[] args) {
        // ~ 按位取反，把存储的二进制位取反即可...
        // | 按位或
        // & 按位与

        int j = ~1;
        System.out.println(j);
        final String jstring = Integer.toBinaryString(j);
        System.out.println(jstring);

        int i =  1 & ~2;
        final String string = Integer.toBinaryString(2);
        final String string1 = Integer.toBinaryString(~2);
        System.out.println(i);
        System.out.println(string);
        System.out.println(string1);



        int k = 1 | 1;
        int l = 1 | 4;
        int m = 1 | 8;
        int n = 1 | 16;

        System.out.println(k);
        System.out.println(l);
        System.out.println(m);
        System.out.println(n);

        int interestSet = 6;

        boolean isInterestedInRead    = (interestSet & SelectionKey.OP_READ)  != 0;
        boolean isInterested2  = (interestSet & 3) != 0;
        boolean isInterestedInWrite   = (interestSet & SelectionKey.OP_WRITE) != 0;
        boolean isInterestedInConnect = (interestSet & SelectionKey.OP_CONNECT) != 0;
        boolean isInterestedInAccept  = (interestSet & SelectionKey.OP_ACCEPT) != 0;



        System.out.println("isInterestedInRead-->" + isInterestedInRead);
        System.out.println("isInterested2-->" + isInterested2);

        System.out.println("isInterestedInWrite-->" + isInterestedInWrite);
        System.out.println("isInterestedInConnect-->" + isInterestedInConnect);
        System.out.println("isInterestedInAccept-->" + isInterestedInAccept);
    }
}
